package nix.spring.tx.service;

import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import nix.spring.tx.dao.AccountDao;

// 注解事务可以加在类上，也可以加在方法上，方法注解覆盖类注解
// @Transactional(isolation=Isolation.REPEATABLE_READ,propagation=Propagation.REQUIRED,readOnly=true)
public class Account3ServiceImpl implements AccountService {

	private AccountDao accountDao;

	public void setAccountDao(AccountDao accountDao) {
		this.accountDao = accountDao;
	}

	@Override
	@Transactional(isolation=Isolation.REPEATABLE_READ,propagation=Propagation.REQUIRED,readOnly=false)
	public void transfer(Integer from, Integer to, Double money) {

		accountDao.subMoney(from, money);
		int i = 1 / 0;
		accountDao.addMoney(to, money);
	}

}
